// 投诉模块接口文档
import { api } from 'boot/axios'

/** 房源管理参数：
 * complainantName	String	是	投诉人姓名
 * complaintHouseNumber	String	是	投诉房屋编号
 * complaintContent	String	是	投诉内容
 * phoneNumber	String	是	投诉人联系电话
 * resolved	String	否	是否已解决（默认未解决）
 **/
export interface IComplaintParam {
  complainantName: string
  complaintHouseNumber: string
  complaintContent: string
  phoneNumber: string
  resolved?: string
}
export type IEditComplaintParam = Partial<IComplaintParam> & {
  complaintId: number
}

const COMPLAINT_URL = '/house/complaint'
const COMPLAINT_PAGE_URL = '/house/complaint/page'
const COMPLAINT_LIST_URL = '/house/complaint/list'

// Complaint
export function addComplaint(data: IComplaintParam) {
  return api.post(COMPLAINT_URL, data)
}
export function editComplaint(data: IEditComplaintParam) {
  return api.put(COMPLAINT_URL, data)
}
export function removeComplaint(id: number) {
  return api.delete(`${COMPLAINT_URL}/${id}`)
}
export function getComplaintById(id: number) {
  return api.get(`${COMPLAINT_URL}/${id}`)
}
export function getComplaintList() {
  return api.get(COMPLAINT_LIST_URL)
}
export interface IComplaintQueryParams {
  pageNum: number
  pageSize: number
  resolved?: string
  complaintHouseNumber?: string
}
export function getComplaintPageList(oArg: IComplaintQueryParams) {
  const params: IComplaintQueryParams = {
    pageNum: oArg.pageNum || 1,
    pageSize: oArg.pageSize || 10
  }
  if (oArg.resolved) {
    params.resolved = oArg.resolved
  }
  if (oArg.complaintHouseNumber) {
    params.complaintHouseNumber = oArg.complaintHouseNumber
  }
  return api.get(COMPLAINT_PAGE_URL, { params })
}
